package com.sugon.stream;

import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import static  java.util.stream.Collectors.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 函数式数据处理
 * 集合：面向数据存储
 * 流：面向数据计算
 *     内部迭代与外部迭代
 *     提高并发效率，简化编程
 */
public class TestStream_simple {

    static List<String> list = Arrays.asList("luoy","luoy", "yangj", "fengch", "yangj", "luoy");
    public static void main(String[] args) {

        Stream<String> stream = list.stream();
        //中间操作：获取集合前三个元素
        Stream<String> stream2 = stream.limit(3);
        //终端操作：转换为集合
        List<String> result = stream2.collect(toList());
        result.forEach(System.out::println);

    }

    @Test
    public void test(){
        Stream<String> stream = list.stream();
        //获取长度为4的元素
        Stream<String> stream2 = stream.filter(s -> s.length() == 4);
        //过滤重复元素
        Stream<String> stream3 = stream2.distinct();
        List<String> result = stream3.collect(Collectors.toList());
        result.forEach(System.out::println);
    }

}
